import time
import datetime
from dateutil import tz

TIME_FORMAT = "%Y-%m-%d %H:%M:%S"


def get_week(time_str):
    time_obj = time.strptime(time_str, TIME_FORMAT)
    week = int(time_obj.tm_yday / 7) + 1
    year = time_obj.tm_year % 2000
    return "{}W{}".format(year, str("%02d" % week))


def now_date():
    return time.localtime(time.time())


def now_time():
    return time.time()


def to_time(date):
    return time.mktime(date)


def to_date(t):
    return time.localtime(t)


def format_date(date, f=TIME_FORMAT):
    return time.strftime(f, date)


def parse_date_str(string, f=TIME_FORMAT):
    return time.strptime(string, f)


def utc_now():
    return datetime.datetime.utcnow().timestamp()


def local_to_utc(t):
    return datetime.datetime.utcfromtimestamp(t).timestamp()


def utc_to_local(t_utc):
    return datetime.datetime.fromtimestamp(t_utc).replace(tzinfo=tz.tzutc()).astimezone(tz.tzlocal()).timestamp()


print(now_time())
print(utc_now())
print(local_to_utc(now_time()))
print(utc_to_local(utc_now()))
